<?php
	include "common.php";
	session_start();
	error_reporting(0);
	//error_reporting(0);
	if($_SESSION['logInCheck']!=1){
		header('Location: index.php?loginInfo=false');
	}
	$userFname = $_SESSION['userFname'];
	$userLname = $_SESSION['userLname'];

	$userLink = $_SESSION['userLink'];
	if($userLink!="ceo.php"){
		echo "Sorry, You have no right to visit this page!!";
		exit;
	}
	$timezone_offset = 6; // for getting local time offset hrs
	$systemDate = gmdate('y-m-d', time()+$timezone_offset*60*60);	
	$attendanceSql = "SELECT * FROM attendance WHERE date = '$systemDate' and inTheOffice = 'true'";
	$attendanceSqlQuery = mysql_query($attendanceSql);
	$rows = mysql_num_rows($attendanceSqlQuery);	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="index.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="hr_attendance.css" />
<link rel="icon" type="image/ico" href="images/favicon.ico"></link> 
<link rel="shortcut icon" href="images/favicon.ico"></link>
<script src="curvycorners.src.js" type="text/javascript"></script>
<script src="login.js" type="text/javascript"></script>
<title><?php echo "Welcome to ".$userFname." ".$userLname; ?></title>
</head>

<body>
<div class="main_div_other">
	<p><img src="images/creato_logo.jpg" /></p>
    <p id="creatobd">www.creatobd.com</p>
    <p id="date"><script>document.write(new_month+" "+new_date+", "+old_date.getFullYear()+" || "+new_day);</script></p>
    <div class="other_page_icons">
    	<div class="new_notification">
        	<img src="images/arrow_up.JPG" /><?php if ($notification >0){?><p>You have<?php echo " ".$notification." ";?>new notification</p><?php }?>
        </div><!--end of new_notification-->
    	<ul>
        	<a href="ceo.php"><li><div id="home"></div><p>home</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="ceo_employee.php"><li><div id="employee"></div><p>employee</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="on_duty.php"><li><div id="onduty"></div><p>on duty</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="ceo_attendance.php"><li><div id="attendance"></div><p>attendance</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="leave.php"><li><div id="leave"></div><p>leave</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="ceo_notification.php"><li><div id="notification"></div><p>notification</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="ceo_blackbox.php"><li><div id="blackbox"></div><p>black box</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="ceo_notice.php"><li><div id="hrpolicy"></div><p>hr policy</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="index.php"><li><div id="logout"></div><p>log out</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
        </ul>

    </div><!-- end of other_page_icons-->
    
</div><!-- end of main_div_other-->
<div class="othrpage_1">
	 <p>View as : <a href="on_duty.php?check=1">today</a> | <a href="on_duty.php?check=2">week</a> | <a href="on_duty.php?check=3">month</a> | <a href="on_duty.php?check=4">late</a> | <a href="on_duty.php?check=5">on time</a> | <a href="on_duty.php?check=6">by name</a></p>
</div><!-- end of othrpage_1-->
<div class="human_portal">
  		<p>creato human resourse portal</p>
</div><!-- end of human_portal-->

	<div class="page_content1">
	<?php
		$checkSubmit = $_GET['check'];
		if ($checkSubmit == 1)
		{
	?>
  		<table align="center"  border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
        	<tr class="table_header_1"  valign="top">
            	<td align="center" colspan="8">Employees In Office Now</td>
            </tr>
			<tr valign="top" class="table_header_2">
				<td width="100px"><p>Employee Id</p></td>				
				<td width="100px"><p>First Name</p></td>
				<td width="100px"><p>Last Name</p></td>				
				<td width="100px"><p>Entry Time</p></td>                
			</tr>
    </table>	
		<table align="center" class="header_page_content" border="0" cellpadding="0" cellspacing="0" width="800px;">
        <?php
		while($data = mysql_fetch_array($attendanceSqlQuery)){
			$collectId = $data['e_id'];
			$collectFnameAndLname = "SELECT * FROM user WHERE e_id='$collectId'";
			$collectFnameAndLnameQuery = mysql_query($collectFnameAndLname);
			$collectFnameAndLnameFetchArray = mysql_fetch_array($collectFnameAndLnameQuery);
		?>
			<tr valign="top" class="table_header_3">
				<td width="100px"><p><?php echo $data['e_id']; ?></p></td>				
				<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['f_name']; ?></p></td>
				<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['l_name']; ?></p></td>
				<td width="100px"><p><?php echo $data['in_time']; ?></p></td>				
			</tr>
		<?php
			}
		?>
		</table>
		<?php 
		}
		if ($checkSubmit == 2)
		{
			$dateFrom = strtotime(date("y-m-d", strtotime($systemDate))." -7 day");
			$dateFrom = date('y-m-d', $dateFrom);
			
			$sql = "SELECT * FROM attendance WHERE status=0 AND date between '$dateFrom' AND '$systemDate'";
			$sqlQuery = mysql_query($sql);
		?>
			<table align="center"  border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
				<tr class="table_header_1"  valign="top">
					<td align="center" colspan="8">Attendance of Last 7 Days</td>
				</tr>
				<tr valign="top" class="table_header_2">
					<td width="100px"><p>Employee Id</p></td>				
					<td width="100px"><p>First Name</p></td>
					<td width="100px"><p>Last Name</p></td>				
					<td width="100px"><p>Date</p></td>
					<td width="100px"><p>Day</p></td>             
				</tr>
    	</table>	
		<table align="center" border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
			
				<?php
					while ($data = mysql_fetch_assoc($sqlQuery))
					{
						$collectId = $data['e_id'];
						$collectFnameAndLname = "SELECT * FROM user WHERE e_id='$collectId'";
						$collectFnameAndLnameQuery = mysql_query($collectFnameAndLname);
						$collectFnameAndLnameFetchArray = mysql_fetch_array($collectFnameAndLnameQuery);
					?>
					<tr class="table_header_3" valign="top">		
						<td width="100px"><p><?php echo $data['e_id'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['f_name'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['l_name'];?></p></td>
						<td width="100px"><p><?php echo $data['date'];?></p></td>
						<td width="100px"><p><?php echo $data['day'];?></p></td>
					</tr>
				<?php 
					}
				?>
		</table>	
		<?php
		}
		if ($checkSubmit ==3)
		{
			$dateFrom = strtotime(date("y-m-d", strtotime($systemDate))." -30 day");
			$dateFrom = date('y-m-d', $dateFrom);
			
			$sql = "SELECT * FROM attendance WHERE status=0 AND date between '$dateFrom' AND '$systemDate'";
			$sqlQuery = mysql_query($sql);	
		?>
			<table align="center"  border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
				<tr class="table_header_1"  valign="top">
					<td align="center" colspan="8">Attendance of Last Month</td>
				</tr>
				<tr valign="top" class="table_header_2">
					<td width="100px"><p>Employee Id</p></td>				
					<td width="100px"><p>First Name</p></td>
					<td width="100px"><p>Last Name</p></td>				
					<td width="100px"><p>Date</p></td>
					<td width="100px"><p>Day</p></td>             
				</tr>
    	</table>	
		<table align="center" border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
				<?php
					while ($data = mysql_fetch_assoc($sqlQuery))
					{
						$collectId = $data['e_id'];
						$collectFnameAndLname = "SELECT * FROM user WHERE e_id='$collectId'";
						$collectFnameAndLnameQuery = mysql_query($collectFnameAndLname);
						$collectFnameAndLnameFetchArray = mysql_fetch_array($collectFnameAndLnameQuery);
					?>	
					<tr class="table_header_3" valign="top">
						<td width="100px"><p><?php echo $data['e_id'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['f_name'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['l_name'];?></p></td>
						<td width="100px"><p><?php echo $data['date'];?></p></td>
						<td width="100px"><p><?php echo $data['day'];?></p></td>
					</tr>
				<?php 
					}
				?>
			
		</table>
		<?php 
		}
		if ($checkSubmit ==4)
		{
		 $sql = "SELECT * FROM attendance WHERE status =0";
		 $sqlQuery = mysql_query($sql);
		?>
			<table align="center"  border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
				<tr class="table_header_1"  valign="top">
					<td align="center" colspan="8">Late </td>
				</tr>
				<tr valign="top" class="table_header_2">
					<td width="100px"><p>Employee Id</p></td>				
					<td width="100px"><p>First Name</p></td>
					<td width="100px"><p>Last Name</p></td>				
					<td width="100px"><p>Date</p></td>
					<td width="100px"><p>Day</p></td>             
				</tr>
    	</table>	
		<table align="center" border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
				<?php
					while ($data = mysql_fetch_assoc($sqlQuery))
					{
						$collectId = $data['e_id'];
						$collectFnameAndLname = "SELECT * FROM user WHERE e_id='$collectId'";
						$collectFnameAndLnameQuery = mysql_query($collectFnameAndLname);
						$collectFnameAndLnameFetchArray = mysql_fetch_array($collectFnameAndLnameQuery);
					?>
					<tr class="table_header_3" valign="top">
						<td width="100px"><p><?php echo $data['e_id'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['f_name'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['l_name'];?></p></td>
						<td width="100px"><p><?php echo $data['date'];?></p></td>
						<td width="100px"><p><?php echo $data['day'];?></p></td>
					</tr>		
				<?php 
					}
				?>
			
		</table>

		<?php 
		}
		if ($checkSubmit ==5)
		{
			$sql = "SELECT * FROM attendance WHERE status=1";
			$sqlQuery = mysql_query($sql);
		?>
			<table align="center"  border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
				<tr class="table_header_1"  valign="top">
					<td align="center" colspan="8">On Time</td>
				</tr>
				<tr valign="top" class="table_header_2">
					<td width="100px"><p>Employee Id</p></td>				
					<td width="100px"><p>First Name</p></td>
					<td width="100px"><p>Last Name</p></td>				
					<td width="100px"><p>Date</p></td>
					<td width="100px"><p>Day</p></td>             
				</tr>
    	</table>	
		<table align="center" border="0" cellpadding="0" cellspacing="0" class="header_page_content" width="800px;">
				<?php
					while ($data = mysql_fetch_assoc($sqlQuery))
					{
						$collectId = $data['e_id'];
						$collectFnameAndLname = "SELECT * FROM user WHERE e_id='$collectId'";
						$collectFnameAndLnameQuery = mysql_query($collectFnameAndLname);
						$collectFnameAndLnameFetchArray = mysql_fetch_array($collectFnameAndLnameQuery);
					?>
					<tr class="table_header_3" valign="top">
						<td width="100px"><p><?php echo $data['e_id'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['f_name'];?></p></td>
						<td width="100px"><p><?php echo $collectFnameAndLnameFetchArray['l_name'];?></p></td>
						<td width="100px"><p><?php echo $data['date'];?></p></td>
						<td width="100px"><p><?php echo $data['day'];?></p></td>
					</tr>
				<?php 
					}
				?>
		</table>

		<?php 
		}
		
		?>		
    </div>


</body>
</html>